package com.zhyl.demo.controller;

import com.zhyl.demo.entity.InHospital;
import com.zhyl.demo.service.InHospitalService;
import com.zhyl.demo.utils.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yang3
 */
@RestController
@RequestMapping("/inHospital")
public class InHospitalController {
    private final InHospitalService inHospitalService;
    private InHospitalController(InHospitalService inHospitalService)
    {
        this.inHospitalService = inHospitalService;
    }

    @RequestMapping("/getInHospitalInfo")
    public Result getInHospitalInfo(int id)
    {
        if (id<=0)
        {
            return Result.error("-1","参数错误");
        }
        InHospital inHospitalInfo = inHospitalService.getInHospitalInfo(id);
        if (inHospitalInfo!=null){
            return Result.success(inHospitalInfo);
        }else {
            return Result.error("-1","暂无住院信息");
        }
    }

    @RequestMapping("/addInHospital")
    public Result addInHospital(@RequestBody InHospital inHospital)
    {
        if (inHospital==null)
        {
            return Result.error("-1","参数错误");
        }
        Boolean aBoolean = inHospitalService.addInHospital(inHospital);
        if (aBoolean==true){
            return Result.success(inHospital.getId());
        }else {
            return Result.error("-1","添加失败");
        }
    }

}
